<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <script>

    // 寄生组合继承
    function Animal(name) {
      this.name = name
      this.run = function () {
        console.log('跑')
      }
    }
    Animal.prototype.eat = function () {
      console.log('吃')
    }

    // 4.原型式继承
    function sub(obj) {

      function F() { }
      F.prototype = obj
      return new F()
    }
    var con = sub(Animal.prototype)
    // 猫类
    function Cat() {
      this.name = name
      Animal.call(this) //2.构造函数继承
    }
    con.constructor = Cat //修复构造器
    Cat.prototype = con //1.原型链继承 new Animal()
    var tom = new Cat()
    tom.run()
    tom.eat()

  </script>
</body>

</html>